<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('报告名称')" prop="reportName">
            <el-input v-model="form.reportName" :placeholder="$t('报告名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('年份')" prop="nianfen">
            <el-date-picker
              v-model="form.nianfen"
              type="year"
              clearable
              size="small"
              value-format="yyyy"
              placeholder="选择年"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('季度')" prop="jidu">
            <dictSelect
              v-model="form.jidu"
              :clearable="true"
              dictionary="report_type"
              :placeholder="'季度'"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('产品进度（产品管线、专利、研发、报证、生产情况）')" prop="chanpinjindu">
            <el-input v-model="form.chanpinjindu" type="textarea" maxlength="2000" :placeholder="$t('产品进度（产品管线、专利、研发、报证、生产情况）')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('团队（团队情况、核心成员变动情况）')" prop="teamSituation">
            <el-input v-model="form.teamSituation" type="textarea" maxlength="2000" :placeholder="$t('团队（团队情况、核心成员变动情况）')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('业务发展和生产经营（业务进展详细情况、产能产值、再投入等）')" prop="businessDevelopment">
            <el-input v-model="form.businessDevelopment" type="textarea" maxlength="2000" :placeholder="$t('业务发展和生产经营（业务进展详细情况、产能产值、再投入等）')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('市场布局、销售情况（渠道、产品、销量、成本及价格、销售金额等）')" prop="marketLayout">
            <el-input v-model="form.marketLayout" type="textarea" maxlength="2000" :placeholder="$t('市场布局、销售情况（渠道、产品、销量、成本及价格、销售金额等）')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('落地进展（场地、面积、装修、报证、有无签署相应合同）')" prop="landingProgress">
            <el-input v-model="form.landingProgress" type="textarea" maxlength="2000" :placeholder="$t('落地进展（场地、面积、装修、报证、有无签署相应合同）')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('专利（已有专利、在申请专利）')" prop="patent">
            <el-input v-model="form.patent" type="textarea" maxlength="2000" :placeholder="$t('专利（已有专利、在申请专利）')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('荣誉')" prop="rongyu">
            <el-input v-model="form.rongyu" type="textarea" maxlength="2000" :placeholder="$t('荣誉')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('后续（或接洽中）股权融资情况（融资轮数、拟估值、拟融资金额、接洽进展等）')" prop="follow">
            <el-input v-model="form.follow" type="textarea" maxlength="2000" :placeholder="$t('后续（或接洽中）股权融资情况（融资轮数、拟估值、拟融资金额、接洽进展等）')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('银行融资进展、股东借款等')" prop="financingProgress">
            <el-input v-model="form.financingProgress" type="textarea" maxlength="2000" :placeholder="$t('银行融资进展、股东借款等')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('重大事项情况记录')" prop="bigIssuesRecord">
            <el-input v-model="form.bigIssuesRecord" type="textarea" maxlength="2000" :placeholder="$t('重大事项情况记录')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('公司存在的困难、解决方式')" prop="difficulty">
            <el-input v-model="form.difficulty" type="textarea" maxlength="2000" :placeholder="$t('公司存在的困难、解决方式')" show-word-limit />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('公司业务战略和后续工作计划')" prop="followPlan">
            <el-input v-model="form.followPlan" type="textarea" maxlength="2000" :placeholder="$t('公司业务战略和后续工作计划')" show-word-limit />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable
        :list.sync="form.fileList"
        data-type="deal_th_manage"
        :business-id="this.$route.query.companyId"
      />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="deal:management" />
    </div>
  </div>
</template>

<script>
    import { saveCompanyThManagement, getCompanyThManagement } from '@/api/sass/lanwan/companyThManagement'
    export default {
        data() {
            return {
                // 表单参数
                form: {
                  fileList: []
                },
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  reportName: [{ required: true, message: '必填信息',	trigger: 'blur' }],
                  nianfen: [{ required: true, message: '必填信息',	trigger: 'blur' }],
                  jidu: [{ required: true, message: '必填信息', trigger: 'change' }]
                }
            }
        },
        created() {
            this.getDicts('report_type').then(response => {
                this.jiduOptions = response.data
            })
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getCompanyThManagement(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    }).catch(() => {
                      this.loading = false
                    })
                } else {
                    this.reset()
                    this.gainYear()
                    this.loading = false
                }
            },
          // 获取当前年份和当前季度
          gainYear() {
            const myDate = new Date()
            var month = myDate.getMonth() + 1
            if (month >= 1 && month <= 3) {
              this.form.jidu = '1'
            } else if (month >= 4 && month <= 6) {
              this.form.jidu = '2'
            } else if (month >= 7 && month <= 9) {
              this.form.jidu = '3'
            } else {
              this.form.jidu = '4'
            }
            this.form.nianfen = myDate.getFullYear().toString()
          },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    dealId: this.$route.query.id,
                    companyId: this.$route.query.companyId,
                    reportName: undefined,
                    nianfen: undefined,
                    jidu: undefined,
                    chanpinjindu: undefined,
                    teamSituation: undefined,
                    businessDevelopment: undefined,
                    marketLayout: undefined,
                    landingProgress: undefined,
                    patent: undefined,
                    rongyu: undefined,
                    follow: undefined,
                    financingProgress: undefined,
                    bigIssuesRecord: undefined,
                    difficulty: undefined,
                    followPlan: undefined,
                    employmentDemand: undefined,
                    landDemand: undefined,
                    isExportPlan: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveCompanyThManagement(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                }).catch(() => {
                    this.loading = false
                })
           }
        }
    }
</script>
